﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace FSO
{
    /// <summary>
    /// Форма для отображения отчетов
    /// </summary>
    public partial class FormReport : Form, IntefaceObjectForm
    {
        /// <summary>
        /// Заголовок формы
        /// </summary>
        public string Title
        {
            get
            {
                return this.Text;
            }
            set
            {
                this.Text = value;
            }
        }
        private Type _typeParametersPanelType;
        private Control _cntrlParametes;
        /// <summary>
        /// Компонент для отображения параметорв отчета
        /// </summary>
        public Type ParametersPanelType
        {
            get
            {
                return _typeParametersPanelType;
            }
            set
            {
                _typeParametersPanelType = value;
            }
        }
        /// <summary>
        /// Конструктор формы
        /// </summary>
        public FormReport(Type ParametersPanelType, string ReprotPath, string Title)
        {
            InitializeComponent();

            this.Text = Title;
            _reporPath = ReprotPath;
            _typeParametersPanelType = ParametersPanelType;
            this.reportViewer1.ServerReport.ReportServerUrl = new Uri(Properties.Settings.Default.ReportServerUrl);
            this.reportViewer1.ServerReport.ReportPath = ReprotPath;

            _cntrlParametes = Activator.CreateInstance(_typeParametersPanelType) as Control;
            if (_cntrlParametes != null)
            {
                _cntrlParametes.Location = new Point(radGroupBoxParams.Padding.Left, radGroupBoxParams.Padding.Top);
                //cntrlParametersPanel.Dock = DockStyle.Fill;
                radGroupBoxParams.Controls.Add(_cntrlParametes);
                panelParams.Height = _cntrlParametes.Height + 10;
            }
        }

        private void FormReport_Load(object sender, EventArgs e)
        {
            this.LoadParams();
            this.reportViewer1.RefreshReport();
        }
        /// <summary>
        /// Подгружает параметры для отчета
        /// </summary>
        private void LoadParams()
        {
            Reports.IReportParamList repParamList = _cntrlParametes as Reports.IReportParamList;
            if (repParamList != null)
            {
                this.reportViewer1.ServerReport.SetParameters(repParamList.Parameters);
            }
        }


        #region IntefaceObjectForm Members

        public int Save()
        {
            return 0;
        }

        public int RefreshForm()
        {
            return 0;
        }
        private string _reporPath;
        public string FormName
        {
            get { return _reporPath; }
        }

        #endregion

        private void reportViewer1_ReportRefresh(object sender, CancelEventArgs e)
        {
            this.LoadParams();
        }
    }
}
